<template>
  <div id="app" @mousemove="moveEvent" @click="moveEvent">
    <router-view />
  </div>
</template>

<script>
import publicAPI from '@/utils/api/public/public'
export default {
  name: 'App',
  data() {
    return {
      timmer: null
    }
  },
  methods: {
    moveEvent: function() {
      const path = ['/login']
      if (!path.includes(this.$route.path)) {
        clearTimeout(this.timmer)
        this.init()
      }
    },
    init: function() {
      this.timmer = setTimeout(() => {
        this.logout()
      }, 1000 * 60 * 19)
    },
    async logout() {
      publicAPI.logoutAPI({ _csrf: sessionStorage._csrf }).then(response => {
        if (response.data.flag === 'success') {
          sessionStorage.clear()
          location.reload()
          // this.$router.replace(`/login?redirect=${this.$route.fullPath}`)
          this.$router.push(`/login`)
        }
      }).catch(error => {
        console.log(error)
      })
    }
  }
}
</script>
